package com.lagou.controller;

import com.lagou.domain.PromotionSpace;
import com.lagou.domain.ResponseResult;
import com.lagou.service.PromotionSpaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/promotionSpace")
public class PromotionSpaceController {
    @Autowired
    private PromotionSpaceService promotionSpaceService;

    @RequestMapping("/findAllPromitionSpace")
    public ResponseResult findAllPromitionSpace() {
        return new ResponseResult(true, 200, "success", promotionSpaceService.findAllPromotionSpace());
    }

    @RequestMapping("/savePromotionSpace")
    public ResponseResult saveOrUpdatePromotionSpace(@RequestBody PromotionSpace promotionSpace) {
        if (promotionSpace.getId() == null) {
            promotionSpaceService.savePromotionSpace(promotionSpace);
        } else {
            promotionSpaceService.updatePromotionSpace(promotionSpace);
        }
        return new ResponseResult(true, 200, "success", null);
    }

    @RequestMapping("/findPromotionSpaceById")
    public ResponseResult findPromotionSpaceById(Integer id) {
        return new ResponseResult(true, 200, "success", promotionSpaceService.findPromotionSpaceById(id));
    }
}
